<?php
/**
 * @Author: Marte
 * @Date:   2020-04-02 11:04:21
 * @Last Modified by:   Marte
 * @Last Modified time: 2020-04-02 12:08:28
 */
class Facade{
	protected static $instances = [];

	// 指定代理对象
    protected static function getFacadeClass()
    {
        throw new RuntimeException('Facade does not implement getFacadeClass method.');
    }

    //调用实际类的方法
    public static function __callStatic($method, $params){
        $object = static::getInstance();

        // 执行对应的方法
        // return $object->{$method}(...$params);
        return call_user_func_array([$object, $method], $params);
    }

    public static function getInstance(){
    	// 获取
        $class = static::getFacadeClass();

        if (\is_object($class)) {
            return $class;
        }

        if (isset(static::$instances[$class])) {
            return static::$instances[$class];
        }
        // 解析
        return static::$instances[$class] = new $class();
    }

}